<?php
    function get_real_ip() {
      $ip=false;
      if(!empty($_SERVER["HTTP_CLIENT_IP"]))
        $ip = $_SERVER["HTTP_CLIENT_IP"];
      if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
        if ($ip) {
          array_unshift($ips, $ip);
          $ip = FALSE;
        }
        for ($i = 0; $i < count($ips); $i++) {
          if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
            $ip = $ips[$i];
            break;
          }
        }
      }
      return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
    }
    function get_set_cookie_id() {
      if (! $HTTP_COOKIE_VARS['UID']) {
        $ip = get_real_ip();
        $timestamp = microtime();
        $UID=md5($ip . $timestamp);
        setcookie("UID", $UID, time() + 1 * 365 * 24 * 60 * 60);
        return $UID;
      } else {
        return $HTTP_COOKIE_VARS['UID'];
      }
    }
    $cookieid=get_set_cookie_id();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>找人么</title> 
  <meta name="description" content=""/> 
  <meta name="keywords" content="" /> 
  <link rel="stylesheet" type="text/css" href="css/css2.css" /> 
  <style type="text/css">
    body {margin:0px;padding:0px;margin-left:auto;margin-right:auto;text-align:center;background:#FFFFFF;}
    h1, h2, h4, h5, h6,p,ul,li,form	{margin:0;padding:0;}
    body, table,  p, ul, td, dt, dd, select, input {font:normal 12px verdana,sans-serif}
    a.title {text-decoration:none;color:#145CA6;cursor:pointer;}
    a.title:hover {text-decoration:underline;cursor:pointer;}
   .h3{float:right;}
   #head{width:1002px; background-color:#e8f3ff; margin:0 auto;}
   .l{float:left;}
    
  </style>
  <!--[if IE]><script language="JavaScript" type="text/javascript" src="js/excanvas.min.js"></script><![endif]-->
  <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.flot.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.flot.selection.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.flot.pie.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.tipsy.js"></script>
  <!-- <script language='JavaScript' type='text/JavaScript' src="js/js.js"></script> -->
  <script language='JavaScript' type='text/JavaScript' src="js.js"></script>

  <script language='JavaScript' type='text/JavaScript'>

  function drawTrend(blog_trends, mint, maxt) {
  
    var last_x = maxt;

    var zoom_options = {
        lines: { show: true },
        points: { show: true },
        xaxis: {
            mode: "time",
            minTickSize: [1, "day"],
            min: mint,
            max: maxt,
        },
        yaxis: {
            minTickSize: 1
        },
        legend: {show: true},
    };

    var zoom_data = $.plot($("#zoom_data"), blog_trends, zoom_options);

    $("#zoom_data").bind("plotselected", function(event, ranges, item) {
        zoom_data = $.plot($("#zoom_data"), blog_trends, 
                           $.extend(true, {}, zoom_options, {
                                xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
                           }));
    });

  

    var overview_data = $.plot($("#overview_data"), blog_trends, {
        selection: {
            mode: "x"
        },
        lines: { show: true },
        shadowSize: 0,
        xaxis: {
            mode: "time",
         
            min: mint,
            max: maxt,
        },
        yaxis: {
            ticks: [],
            autoscaleMargin: 0.1
        },
        legend: {show: true}
    });

    $("#overview_data").bind("plotselected", function (event, ranges, item) {
        var from = new Date(ranges.xaxis.from);
        var to = new Date(ranges.xaxis.to);
        var from_str, to_str;
        if (from.getYear() > 1000)
            from_str = "" + from.getYear() + "." + (from.getMonth() + 1) + "." + from.getDate() + "";
        else
            from_str = "" + (from.getYear() + 1900) + "." + (from.getMonth() + 1) + "." + from.getDate() + "";
        if (to.getYear() > 1000)
            to_str = "" + to.getYear() + "." + (to.getMonth() + 1) + "." + to.getDate() ;
        else
            to_str = "" + (to.getYear() + 1900) + "." + (to.getMonth() + 1) + "." + to.getDate();
        $("#selection").text("自 " + from_str + " 到 " + to_str + " 的文章主题分布");
        zoom_data.setSelection(ranges);
	


	updatePie(from, to);
    });

   
    var onemonthago = maxt - (365 * 24 * 60 * 60 * 1000);
    if (onemonthago > mint)
        overview_data.setSelection({ xaxis: { from: onemonthago, to: maxt }});
    else
        overview_data.setSelection({ xaxis: { from: mint, to: maxt }});
  }

  </script>
</head> 

<body>

  <?php
    $authorid=$_GET[qzoneid];
    if(!isset($_GET["page"]) || !is_numeric($_GET["page"])) {
      $page=1;
    }else{
      $page=intval($_GET["page"]);
    }
    $pagesize=20;

    $con = mysql_connect("192.168.1.100","root","linux123");
    if (!$con)
      die('Could not connect: ' . mysql_error());
    if ($_GET[qzoneid]) {
      $type = 'qzone';
      @mysql_select_db("crawlqzone", $con);
      $qzoneid = $_GET[qzoneid];
      @mysql_query("set names utf-8");
      $sql1 = mysql_query("select count(*) from blog where authorid='" . $_GET[qzoneid] . "'", $con);
      $total=mysql_fetch_array($sql1);
      $total=$total[0];
      $offset = $pagesize * ($page - 1);
      $sql = mysql_query("select blog_id, title, time, num_comment, num_read, cat_id, cat_name, seq from blog where authorid='" . $_GET[qzoneid] . "' ORDER BY time DESC LIMIT $offset, $pagesize ", $con);
      $profile = mysql_query("select nickname,sex,age,birthday,bloodtype,country,province,city,hco,hp, hc,marriage,spacename,descri,interest,career,company,cco,cp,cb,cr from profile where uin='" . $_GET[qzoneid] . "'", $con);
    } else if ($_GET[qqshuqianid]) {
      $type = 'qqshuqian';
      @mysql_select_db("crawlqq", $con);
      $qqshuqianid = $_GET[qqshuqianid];
      @mysql_query("set names utf-8");
      $sql1 = mysql_query("select count(*) from link where authorid='" . $_GET[qqshuqianid] . "'", $con);
      $total=mysql_fetch_array($sql1);
      $total=$total[0];
      $offset = $pagesize * $page;
      $sql = mysql_query("select id, title, url, time, linkcount from link where authorid='" . $_GET[qqshuqianid] . "' ORDER BY time DESC LIMIT $offset, $pagesize ", $con);
      $profile = mysql_query("select nickname,sex,age,birthday,bloodtype,country,province,city,hco,hp, hc,marriage,spacename,descri,interest,career,company,cco,cp,cb,cr from profile where uin='" . $_GET[qqshuqianid] . "'", $con);
    }
    {
            $info_p=mysql_fetch_array($profile);
            $nickname=$info_p[0];
            $sex=$info_p[1];
            $age=$info_p[2];
            $birthday=$info_p[3];
            $bloodtype=$info_p['bloodtype'];
            $country=$info_p[5];
            $province=$info_p[6];
            $city=$info_p[7];
            $hco=$info_p[8];
            $hp=$info_p[9];
            $hc=$info_p[10];
            $marriage=$info_p[11];
            $spacename=$info_p[12];
            $descri=$info_p[13];
            $interest=$info_p[14];
            $career=$info_p[15];
            $company=$info_p[16];
            $cco=$info_p[17];
            $cp=$info_p[18];
            $cb=$info_p[19];
            $cr=$info_p[20];
    }
    if($total%$pagesize==0) {
      $pagecount=intval($total/$pagesize);
    } else {
      $pagecount=ceil($total/$pagesize);
    }
    if (!$pagecount)
      $pagecount = 1;
  ?>
    <div id="head">
      <div class="hd">
        <div class="l" style="width:230px;padding:3px;">
          <div style="padding:0 10px">
            <a href="index.html" title="找人么"><img src="img/i.gif" alt="找人么" width="174" height="36" style="border:0"/></a>
          </div>
        </div>
        <div class="h3" style="padding:12px 10px"> ┊ <a href="index.html" class="ce">首页</a> ┊ <a href="help.html" class="ce">帮助 </a> </div>
        <div class="c"></div>
      </div>
    </div>
  <div class="h10">&nbsp;</div>
  <h4 class="clear"  >
    <?php echo $authorid;?>&nbsp;的兴趣名片
  </h4>
  <div class="h10">&nbsp;</div>

  <div id="main" class="w910"> 

  
    <table><tr>
    <td>
      <div id="trend_container">
        <div id="selection">&nbsp;</div>
        <div id="zoom_data">&nbsp;</div>
        <div id="overview_data">&nbsp;</div>
      </div>
    </td>
    <td>
      <div id="graph" class="pie-graph-big"></div>
    </td>
    </tr></table>
    <div class="h20">&nbsp;</div>
   

    <div class="rc1"></div>
    <div class="lc1">
      <div class="mbox1">
        <table width='600'>
          <tr>
            <td width='80' align='right' style='color:#888'>昵称：</td>
            <td width='120' align='left'> <?php echo $nickname ?> </td>
            <td width='80' align='right' style='color:#888'>年龄：</td>
            <td width='120' align='left'><?php echo $age?></td>
            <td width='80' align='right' style='color:#888'>生日：</td>
            <td width='120' align='left'><?php echo $birthday ?> </td>
          </tr>
          <tr>
            <td align='right' style='color:#888'>居住地：</td>
            <td align='left'><?php echo $country, $province, $city ?></td>
            <td align='right' style='color:#888'>婚姻状况：</td>
            <td align='left'><?php if($marriage==1) echo "未婚"; else if($marriage==2) echo "已婚"; else echo "保密"; ?></td>
            <td align='right' style='color:#888'>职业：</td>
            <td align='left'><?php echo $career; ?></td>
          </tr>
        </table>
      </div>

      <div class="mbox1">

        <ul class="linklist" id="ajax_list"> 
          <li> 
            <h3 class="title">
              <div class="text">
                <?php
                    if ($type == 'qqshuqian') 
                        echo "$authorid &nbsp; 的收藏总数&nbsp; $total";
                    else if ($type == 'qzone')
                        echo "$authorid &nbsp; 的博客文章总数&nbsp; $total";
                ?>
              </div>
            </h3> 
          </li> 
          <?php
            $blog_trends = array();
            while($info=mysql_fetch_array($sql)){
              if ($type == 'qzone') {
                $blog_id=$info[0];
                $title=$info[1];
                $time=$info[2];
               
                $num_comment=$info[3];
                $num_read=$info[4];
                $cat_id=$info[5];
                $cat_name=$info[6];
              
                $url='blog.php?hostuin=' . $qzoneid . '&blogid=' . $blog_id;
                if (! $blog_trends[$cat_name]) {
                    $blog_trends[$cat_name] = array();
                }
                if (! $blog_trends[$cat_name][strtotime($time)]) {
                    $blog_trends[$cat_name][strtotime($time)] = array();
                }
                array_push($blog_trends[$cat_name][strtotime($time)], $blog_id);
              } else if ($type == 'qqshuqian') {
                $id=$info[0];
                $title=$info[1];
                $url=$info[2];
                $time=$info[3];
               
                $linkcount=$info[4];
              }
          ?>
          <li> 
            <table class="list lp"> 
              <tr>
                <td class="linktitle">
                  <h3>
                    <a href="<?php echo $url?>" class="title" target="_blank" rel="nofollow"><?php echo $title?></a>
                  </h3>
                </td>
                <td class="linkcount"><?php list($d, $t) = split(" ", $time); echo $d; ?></td> 
              </tr> 
              <tr>
                <td class="linktags">分类:&nbsp;<?php if ($type == 'qzone') echo $cat_name; else if ($type == 'qqshuqian') echo " "; ?>&nbsp;</td> 
                <td class="linkadd" align="right"><a href="" class="add">是</a>&nbsp;|&nbsp;<a class="add" href="" title="查看详细信息">详细信息</a></td>
              </tr> 
              <tr> 
                <td class="linkdesc">评论:<?php echo $num_comment; ?> &nbsp;阅读:<?php echo  $num_read; ?> &nbsp; </td>
                <td></td>
              </tr>
            </table>
          </li>
          <?php
            }
            array_push($blog_trends[$cat_name][strtotime($time)], $blog_id);

            $blog_trends_json = array();
            $maxt = strtotime('1971-01-01')*1000;
            $mint = strtotime('now')*1000;
            foreach($blog_trends as $cat_name => $v) {
                $value = array();
                foreach($v as $t => $a) {
                  $t *= 1000; 
                  array_push($value, array($t, count($a)));
                  if ($t < $mint)
                      $mint = $t;
                  if ($t > $maxt)
                      $maxt = $t;
                }
               
                array_push($blog_trends_json, array('label'=>$cat_name, 'data'=>$value));
            }
            $blog_trends_json = json_encode($blog_trends_json);
          ?>
        </ul>

        <h3 class="title">
          <div class="more"><div class="pager"></div></div>
        </h3>

        <div id="search_hits">
          <table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="351">
                <div align="left">
                  共&nbsp;<?php echo $total;?>&nbsp;篇&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $pagecount;?>&nbsp;页
                </div>
              </td>
              <?php
                if($page>1) $pre_page_num=$page-1;
                else $pre_page_num=1;
                if($page<$pagecount) $next_page_num=$page+1;
                else $next_page_num=$pagecount;
              ?>
              <td width="199">
                <div align="right">
                <?php
                  if ($type == "qzone") {
                ?>
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qzoneid=<?php echo $qzoneid?>&page=1" class="a1">首页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qzoneid=<?php echo $qzoneid?>&page=<?php echo $pre_page_num?>" class="a1">上一页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qzoneid=<?php echo $qzoneid?>&page=<?php echo $next_page_num?>" class="a1">下一页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qzoneid=<?php echo $qzoneid?>&page=<?php echo $pagecount?>" class="a1">尾页</a>
                <?php
                  } else {
                ?>
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qqshuqianid=<?php echo $qqshuqianid?>&page=1" class="a1">首页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qqshuqianid=<?php echo $qqshuqianid?>&page=<?php echo $pre_page_num?>" class="a1">上一页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qqshuqianid=<?php echo $qqshuqianid?>&page=<?php echo $next_page_num?>" class="a1">下一页</a>&nbsp;
                  <a href="<?php echo $_SERVER["PHP_SELF"]?>?qqshuqianid=<?php echo $qqshuqianid?>&page=<?php echo $pagecount?>" class="a1">尾页</a>
                <?php
                  }
                ?>
                </div>
              </td>
            </tr>
          </table>
        </div>

      </div> 
    </div> 
  </div> 

  <div class="h30">&nbsp;</div>
  <div id="b" style="width:1000px;background:#fff; margin:0 auto;color:#777">
   <center>
    <table align="center" class="footer">
      <tr>
        <td valign="top">
          <a href="feedback.php">意见反馈</a>
          &nbsp; &nbsp;
          <a href="help.html">帮助中心</a>
<!--
          &nbsp; &nbsp;
          <a href="corporation.html">网站合作</a>
-->
          &nbsp; &nbsp;
          <a href="about.html">关于我们</a>
          &nbsp; &nbsp;
          <a href="contact.html">联系方式</a>
          &nbsp; &copy; 2009 zhaoren.me
          &nbsp; &nbsp;
          <!-- <a href="http://www.miibeian.gov.cn/" target="blank" class="g">沪ICP备10009568号</a> -->
          沪ICP备10009568号
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        </td>
      </tr>
    </table>
   </center>
  </div>
  <div class="h30">&nbsp;</div>
  <?php
        

       
        if(!isset($type)){
                echo "location.href='no_pie_err.html'";
        }
        $cat_names = array();
        $blog_ids = array();
        $weights = array();
	$cat_keywords = array();
	$keywords = "";
	$cat_ids = array();
	$cat_times = array();
	$id_conditions = "";
	for($i=0; $i<13; $i++){
		array_push($cat_times, array());
	}
        if ($type == 'qqshuqian')
            $pie_result = mysql_query("select * from userpie where id=$qqshuqianid");
        else if ($type == 'qzone')
            $pie_result = mysql_query("select * from userpie where id=$qzoneid");
        while($row = mysql_fetch_array($pie_result)){
                array_push($cat_names, $row["cat_name"]);
                array_push($blog_ids, explode('@@', $row["blog_ids"]));
                array_push($cat_ids, $row["cat_id"]);
                array_push($weights, count(explode('@@', $row["blog_ids"])));
		$keywords = implode(' ', array_slice(explode('@@', $row["keywords"]), 0, 5));
		array_push($cat_keywords, $keywords);

		
		$id_conditions = "blog_id='";
		$id_conditions .= implode("' or blog_id='", explode('@@', $row["blog_ids"]));
		$snt = "select * from blog where authorid='" . $qzoneid . "' and (" . $id_conditions . "')";
</script>";
		$search_time_sql = mysql_query($snt);
		while($time_row = mysql_fetch_array($search_time_sql)){
			if ($cat_times[$row["cat_id"]-1])
			    array_push($cat_times[$row["cat_id"]-1], $time_row["time"]);
		}
        }
        $cat_name_json = json_encode($cat_names);
        $blog_ids_json = json_encode($blog_ids);
        $weights_json = json_encode($weights);
	$cat_keywords_json = json_encode($cat_keywords);
        $cat_id_json = json_encode($cat_ids);
	$qzoneid_json = json_encode($qzoneid);
	$cat_times_json = json_encode($cat_times);
	$id_conditions_json = json_encode($id_conditions);
        echo "<script>
                var cat_name_js = $cat_name_json;
                var cat_id_js = $cat_id_json;
                var qzoneid_js = $qzoneid_json;
                var blog_ids_js = $blog_ids_json;
                var weights_js = $weights_json; 
		var cat_keywords_js = $cat_keywords_json;
		var cat_times_js = $cat_times_json;
		var id_conditions_js = $id_conditions_json;
                drawPie(cat_name_js, weights_js, qzoneid_js, cat_id_js, cat_times_js);

                var blog_trends_js = $blog_trends_json;
		var mint_js = $mint;
		var maxt_js = $maxt;
                drawTrend(blog_trends_js, mint_js, maxt_js);
              </script>";

        function write_to_search_log($ci, $keywords, $clickseq, $rank, $type, $userid)
        {
          $filename = "/var/souren/souren.log";
          if($fd = @fopen($filename, "a")) {
            $str = "$ci\t[$keywords]\t$rank\t$clickseq\t$type\t$userid\n";
            fputs($fd, $str);
            fclose($fd);
          }
        }
        if ($cookieid && $_GET[keywords] && $_GET[clickseq] && $_GET[rank] && $type && $_GET[$type . 'id'])
            write_to_search_log($cookieid, $_GET[keywords], $_GET[clickseq], $_GET[rank], $type, $_GET[$type . 'id']);
  ?>
  </body> 
</html>

